package priv.pront.code.robot.roboCom_na_2022.ben;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-08-15 19:22
 */
public class RC_u1_智能红绿灯 {

    static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static int left = -1, right = -1, n;
    static boolean flag = true;
    static int[] a;

    public static void main(String[] args) throws IOException {
        st.nextToken();
        n = (int) st.nval;
        a = new int[n];
        for (int i = 0; i < n; i++) {
            st.nextToken();
            a[i] = (int) st.nval;
        }
        for (int i = 0; i < n; i++) {
            if(a[i] > right && left != -1){
                flag = true;
                System.out.println(left + " " + (right - 1));
                left = -1;
            }
            if(a[i] > left  && a[i] < right && flag){
                right += 15;
                flag = false;
            }
            if(a[i] > left && a[i] < right) continue;
            if (left == -1) left = a[i] + 15;
            right = left + 30;
        }
        System.out.println(left + " " + (right - 1));
    }
}
